<%@ page language="java" import="java.util.*,com.zjf.entity.*,com.zjf.dao.*,com.zjf.dao.impl.*" pageEncoding="utf-8"%>
<%@page import="com.zjf.catchs.ArticleCatch"%>
<%@ include file= "loadDatas.jsp"%>
<%! 
	private List<Review> reviews = new ArrayList<Review>();
	private Article article = new Article();
	//登录用户
	private User loginUser;
	private long id;
%>
<%
	
	try{
		List<Article> articles = (List<Article>)application.getAttribute("articles");
		id = Long.parseLong(request.getParameter("id"));
		loginUser = (User)session.getAttribute("loginUser");
		ArticleDao dao = new ArticleDaoImpl();
		article = articles.get(ArticleCatch.getIndex((int)id,articles));
		dao.view(id);
		//new ArticleCatch().updateCatch2((int)id,application);
		ReviewDao dao1 = new ReviewDaoImpl();
		reviews = dao1.queryReviewsByA_id(id);
		
		if(article==null){
			response.sendRedirect("error.jsp?id=107");
			return;
		}
	}catch(NumberFormatException e1){
		e1.printStackTrace();
		response.sendRedirect("error.jsp?id=107");
		
	}catch(Exception e){
		
		
		out.println(e.toString());
		//response.sendRedirect("error.jsp?id=107");
	}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title><%=article.getTitle() %></title>

<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/style/style.css" />
	<!-- editor -->
<script src="<%=request.getContextPath() %>/kindeditor/kindeditor-min.js"></script>
<script  src="<%=request.getContextPath() %>/kindeditor/en.js"></script>
		<script>
		
			
			var editor;
			KindEditor.ready(function(K) {
				editor = K.create('textarea[name="content"]', {
					resizeType : 1,
					allowPreviewEmoticons : false,
					allowImageUpload : false,
					items : [
						'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
						'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
						'insertunorderedlist', '|', 'emoticons', 'image', 'link']
				});
			});
		
			
		</script>
<!-- end of editor -->
  </head>
  
  <body><center>
  <div id ="wrap">
     <jsp:include page="head.jsp"></jsp:include>
     <font size=2>欢迎您<%=loginUser==null?"":":"+loginUser.getUsername() %>，您的身份是：<%=loginUser==null?"游客":User.permissonName[loginUser.getPermisson()] %>		    </font>
			&nbsp;<%=loginUser!=null?"<a href='userMg.jsp?id="+loginUser.getId()+"'>控制面板</a>":"" %><%=loginUser!=null&&loginUser.getPermisson()==2?"|<a href='admin/index.jsp'>管理后台</a>":"" %>
     <br/>
	 <center>
	 <div id="center_pad1">
		 <div id="title"><%=article.getTitle() %></div>
		 <div id="content"><center><font color=blue>作者：<%=article.getAuthor()%>&nbsp;发表时间：<%=article.getPubDate() %></font></center><%=article.getContent()%></div>
	 	<br/><br/>
	 	<%for(int i=0;i<(reviews.size()>10?10:reviews.size());i++){ %>
	 	<div id="content"><div id="title1"><b><%=reviews.get(i).getTitle()%></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;By:<%=reviews.get(i).getAuthor() %>&nbsp; At &nbsp;<%=reviews.get(i).getPubDate() %>
	 	<% if(loginUser!=null && loginUser.getPermisson()==2){%>
	 	<a href="reviewDelete.do?id=<%=reviews.get(i).getId() %>">删除</a>
	 	<%} %>
	 	</div><br/><%=reviews.get(i).getContent() %></div>
	 	<%} %>
	 	<div><a href="replys.jsp?rid=<%=id %>">查看全部评论</a></div>
	 </div>
	 <div id="center_pad1">
	 
	 <div id="content">
	 <div id="title1">发表评论</div>
	 <form action="review.do?id=<%=article.getId() %>" name="review" method="post">
	 	<p>标题:
	 	  <input name="title" type="text" value="" size="76">
	 </p>
	 	<p>
	 	  <textarea style="width:600px;height:300px;" name="content"></textarea><br>
	 	  <input type="submit" value="确定">
	 	  <input type="reset" value="清除">
	 	  </p>
	 </form>
	 </div>
	 </div>
	 </center>
     <jsp:include page="foot.jsp"></jsp:include>
  </div>
  </center>
  </body>
</html>
